from BNL import BNL
def BBS(len1, len2, dataArray):
    """
    Find the skyline set of sequences using the Bi-Bitmap Skyline (BBS) algorithm.

    Args:
    :param len1: (int)Length of the first sequence.
    :param len2: (int)Length of the second sequence.
    :param dataArray: (list)2D array of data containing the sequences.

    Returns:
    :return list: List of indices corresponding to the skyline set of sequences.

    Algorithm Overview:
    The BBS algorithm finds the skyline set of sequences, which are the non-dominated sequences in terms of two criteria:
    1. More 1s: A sequence is considered better if it has more 1s.
    2. Fewer 0s: If two sequences have the same number of 1s, the one with fewer 0s is considered better.

    The steps involved in the BBS algorithm are as follows:
    - Initialize an empty `skylineSet` to store the indices of skyline sequences.
    - For each sequence `i` in the `dataArray`:
        - Initialize a flag variable `dominated` to False.
        - Iterate through each sequence `j` in the `dataArray`:
            - Skip if `i` and `j` are the same sequence.
            - Initialize two counters `oneCnt` and `zeroCnt` to keep track of the number of 1s and 0s in each sequence.
            - Count the number of 1s and 0s in sequence `i` and sequence `j`.
            - Check the dominance conditions:
                - If sequence `i` has fewer 1s and more 0s than sequence `j`, it is dominated by `j`. Set `dominated` to True and break.
                - If sequence `i` has more 1s and fewer 0s than sequence `j`, it dominates `j`. Remove `j` from `skylineSet` if present.
            - If `dominated` is True, break the loop and check next sequence `i`.
        - If `dominated` is False, add `i` to the `skylineSet`.
    - Return the `skylineSet` containing the indices of the skyline set of sequences.
    """
    # Create an empty resultList list
    resultList = []
    # Iterate through the dataArray
    for i in range(len1):
        # Set a flag to indicate whether the current row is dominated
        dominated = False
        # Iterate through the dataArray
        for j in range(len1):
            # If the current row and the current row's row are the same, skip
            if i == j:
                continue
            # Count the number of 1s in the current row
            oneCntI = dataArray[i].count(1)
            # Count the number of 1s in the current row's row
            oneCntJ = dataArray[j].count(1)
            # Count the number of 0s in the current row
            zeroCntI = len2 - oneCntI
            # Count the number of 0s in the current row's row
            zeroCntJ = len2 - oneCntJ
            # If the number of 1s in the current row is less than the number of 1s in the current row's row and the number of 0s in the current row is greater than the number of 0s in the current row's row, set the flag to True
            if oneCntI < oneCntJ and zeroCntI > zeroCntJ:
                dominated = True
                break
            # If the number of 1s in the current row is greater than the number of 1s in the current row's row and the number of 0s in the current row is less than the number of 0s in the current row's row, check if the current row is in the resultList
            elif oneCntI > oneCntJ and zeroCntI < zeroCntJ:
                # If the current row is in the resultList, remove it from the resultList
                if j in resultList:
                    resultList.remove(j)
        # If the current row is not dominated, add it to the resultList
        if not dominated:
            resultList.append(i)
    # Return the resultList
    output = [dataArray[i] for i in resultList]
    return BNL(len(output), len2, output)